package main

import "fmt"

/**
 * @author: guangcheng
 * @date:   2020/11/13 10:45
 * @version  V1.0
 * @description:
 *
 */
func main() {

	hen1 := 3.2
	hen2 := 5.0
	hen3 := 1.0
	hen4 := 6.1
	hen5 := 7.0
	hen6 := 50.1

	totalWeight := hen1 + hen2 + hen3 + hen4 + hen5 + hen6

	//%.2f 保留2位小数
	avgWeight := fmt.Sprintf("%.2f", totalWeight/6)
	// totalWeight=72.4  avgWeight=12.07 totalType=float64  avgType=string
	fmt.Printf("totalWeight=%v  avgWeight=%v totalType=%T  avgType=%T", totalWeight, avgWeight, totalWeight, avgWeight)

	fmt.Println("\n---------------------------")
	var intArr [3]int
	fmt.Println(intArr)

	intArr[0] = 10
	intArr[1] = 20
	intArr[2] = 30
	fmt.Println(intArr)

	//intArr地址=0xc000010420 intArr[0]地址=0xc000010420 intArr[1]地址=0xc000010428 intArr[2]地址=0xc000010430
	fmt.Printf("intArr地址=%p intArr[0]地址=%p intArr[1]地址=%p intArr[2]地址=%p", &intArr, &intArr[0], &intArr[1], &intArr[2])

	var score [5]float64
	for i := range score {
		fmt.Printf("\n请输入第%d个分数:", i+1)
		fmt.Scanln(&score[i])
	}

	for i := range score {
		fmt.Printf("\n 下标=%v  分数=%v", i, score[i])
	}

	fmt.Println("\n--------------------------------")
	//不同方式给数组进行初始化与赋值
	var arr1 [3]int = [3]int{1, 2, 3}
	fmt.Println("arr1=", arr1)

	var arr2 = [3]int{1, 2, 3}
	fmt.Println("arr2=", arr2)

	var arr3 = [...]int{1, 2, 3}
	fmt.Println("arr3=", arr3)

	//指定下标赋值
	var arr4 = [...]int{1: 800, 0: 900, 2: 999}
	fmt.Println("arr4=", arr4)

	arr5 := [...]string{1: "tom", 0: "jack", 2: "marry"}
	fmt.Println("arr5=", arr5)
}
